package ogloszenia.funkcje;

import javax.faces.context.FacesContext;
import javax.mail.*;
import javax.mail.internet.*;

import java.util.Properties;

public class SimpleMail {
	public void ww(){
		 /*Properties props=new Properties();
		   props.put("mail.smtp.host","localhost");   //  'localhost' for testing
		   Session   session1  =  Session.getDefaultInstance(props,null);
		   String s1 = request.getParameter("text1"); //sender (from)
		   String s2 = request.getParameter("text2");
		   String s3 = request.getParameter("text3");
		   String s4 = request.getParameter("area1");
		   Message message =new MimeMessage(session1);
		  message.setFrom(new InternetAddress(s1));
		  message.setRecipients
		  (Message.RecipientType.TO,InternetAddress.parse(s2,false));
		   message.setSubject(s3);
		   message.setText(s4);  
		   Transport.send(message);
		   out.println("mail has been sent");
		  }*/
	}
	public void wyslij() throws MessagingException{
		//public static void main(String[] args)throws MessagingException{
        Properties props = new Properties();
        props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.host", "smtp.googlemail.com");
        props.setProperty("mail.user", "mateuszhyski1980");
        props.setProperty("mail.password", "mateusz80hyski");

        Session mailSession = Session.getDefaultInstance(props, null);
        //FacesContext mailSession=FacesContext.getCurrentInstance();
        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject("Testing javamail plain");
        message.setContent("This is a test", "text/plain");
        message.addRecipient(Message.RecipientType.TO,
             new InternetAddress("hyski.mateusz@gmail.com"));

        transport.connect();
        transport.sendMessage(message,
            message.getRecipients(Message.RecipientType.TO));
        transport.close();
      }
  }
